package com.xuecheng.controller;

import com.xuecheng.dto.BindTeachplanMediaDto;
import com.xuecheng.dto.SaveTeachplanDto;
import com.xuecheng.dto.TeachplanDto;
import com.xuecheng.po.TeachplanMedia;
import com.xuecheng.service.TeachplanService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 课程计划编辑接口
 */
@RestController
public class TeachplanController {
    @Autowired
    TeachplanService teachplanService;

    /**
     * 查询课程计划树形结构
     * @param courseId
     * @return
     */
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> getTreeNodes(@PathVariable Long courseId){
        return teachplanService.findTeachplanTree(courseId);
    }

    /**
     * 课程计划创建或修改
     * @param saveTeachplanDto
     */
    @PostMapping("/teachplan")
    public void saveTeachplan(@RequestBody SaveTeachplanDto saveTeachplanDto){
         teachplanService.saveTeachplan(saveTeachplanDto);
    }

    /**
     * 根据课程计划id删除
     * @param id
     */
    @DeleteMapping("/teachplan/{id}")
    public void delectTeachplan(@PathVariable Long id){
        teachplanService.deleteTeachplan(id);

    }

    /**
     * 课程计划排序
     * @param moveType  移动类型
     * @param id
     */
    @PostMapping("/teachplan/{moveType}/{id}")
    public void orderByTeachplan(@PathVariable String moveType, @PathVariable Long id){
        teachplanService.orderByTeachplan(moveType,id);

    }

    /**
     * 课程计划和媒资信息绑定
     * @param bindTeachplanMediaDto
     */
    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public void associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        teachplanService.associationMedia(bindTeachplanMediaDto);

    }

    /**
     * 删除课程计划的媒资信息
     * @param teachPlanId
     * @param mediaId
     */
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void deleteTeachplanMedia(@PathVariable Long teachPlanId,@PathVariable String mediaId){
        teachplanService.deleteTeachplanMedia(teachPlanId,mediaId);
    }
}
